package com.feihao.zhou.servlet;

import com.feihao.zhou.domain.Student;
import com.feihao.zhou.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/studentServlet")
public class studentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收前端请求，
        //调用service方法：
        StudentService studentService = new StudentService();
        //获取学生集合：
        List<Student> allStudent = studentService.findAllStudent();

        //将学生集合请求转发到show.jsp:
        req.setAttribute("list", allStudent);

        //zhuangfa :
        req.getRequestDispatcher("/show.jsp").forward(req, resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
